﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:conv="clr-namespace:USElections.Converters;assembly=USElections.Converters">

    <conv:GroupToBackgroundBrushValueConverter x:Key="GroupBackground" />
    <conv:GroupToForegroundBrushValueConverter x:Key="GroupForeground" />
    <conv:StateCodeToFullNameConverter x:Key="statecode" />
    <conv:StateCodeToElectoralVotesConverter x:Key="statecode2" />
    <conv:PartyToColorConverter x:Key="ptc" />

    <DataTemplate x:Key="statesListHeader">
        <!--<TextBlock Text="states"
                   Margin="8,-24,0,0"
                   Style="{StaticResource PhoneTextTitle1Style}" />-->
    </DataTemplate>

    <DataTemplate x:Key="statesGroupHeader">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Border Background="Transparent"
                    Margin="12,8,0,8">
                <Border BorderBrush="{StaticResource PhoneAccentBrush}"
                        BorderThickness="2"
                        Background="Transparent"
                        Padding="8,0,0,0"
                        HorizontalAlignment="Stretch"
                        Height="62">
                    <TextBlock Text="{Binding Key, Converter={StaticResource statecode}}"
                               Foreground="{StaticResource PhoneAccentBrush}"
                               FontSize="48"
                               FontFamily="{StaticResource PhoneFontFamilySemiLight}"
                               HorizontalAlignment="Left"
                               VerticalAlignment="Bottom" />
                </Border>
            </Border>

            <TextBlock Text="{Binding Key, Converter={StaticResource statecode2}, StringFormat='Electoral votes: {0}'}"
                       Style="{StaticResource PhoneTextSubtleStyle}"
                       Grid.Row="1" />
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="statesGroupItem">
            <Border Background="{Binding Converter={StaticResource GroupBackground}}"
                    Height="62"
                    Margin="6"
                    Width="432"
                    HorizontalAlignment="Stretch"
                    IsHitTestVisible="{Binding HasItems}">
            <TextBlock Text="{Binding Key, Converter={StaticResource statecode}}"
                       FontFamily="{StaticResource PhoneFontFamilySemiBold}"
                       FontSize="48"
                       Margin="8,0,0,0"
                       Foreground="{Binding Converter={StaticResource GroupForeground}}"
                       VerticalAlignment="Bottom" />
            <Border.Projection>
                    <PlaneProjection RotationX="-60" />
                </Border.Projection>
            </Border>
    </DataTemplate>

    <DataTemplate x:Key="statesItemTemplate">
        <Grid Margin="12, 6">
            <ItemsControl ItemsSource="{Binding Votes}">
                <ItemsControl.Template>
                    <ControlTemplate>
                        <ItemsPresenter />
                    </ControlTemplate>
                </ItemsControl.Template>

                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>

                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="0,0,0,6">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            
                            <Border Grid.Row="0"
                                    Grid.Column="0"
                                    Height="62"
                                    Width="62"
                                    Background="{Binding Path=Candidate.Party, Converter={StaticResource ptc}}">
                                <TextBlock Text="{Binding Path=NumberOfVotes}" 
                                           HorizontalAlignment="Center"
                                           VerticalAlignment="Center"
                                           Style="{StaticResource PhoneTextLargeStyle}" />
                            </Border>
                            <StackPanel Grid.Row="0"
                                        Grid.Column="1"
                                        VerticalAlignment="Center">
                                <TextBlock Text="{Binding Path=Candidate.FullName}"
                                           Style="{StaticResource PhoneTextLargeStyle}"
                                           TextWrapping="NoWrap" />
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>
    </DataTemplate>
</ResourceDictionary>